package com.demo.design.behavioral.state;

import com.demo.design.behavioral.state.impl.HasMoneyState;
import com.demo.design.behavioral.state.impl.NoneMoneyState;
import com.demo.design.behavioral.state.impl.SaleOutState;

import java.util.HashMap;
import java.util.Map;


public class CandyMachine{

    private State nowState;

    private Integer num = 50;

    private static Map<String, State> STATE_MAP = new HashMap();

    public CandyMachine() {
        STATE_MAP.put("none", new NoneMoneyState(this));
        STATE_MAP.put("has", new HasMoneyState(this));
        STATE_MAP.put("saleout", new SaleOutState(this));

        nowState = STATE_MAP.get("none");
    }

    public void insertCoins() {
        nowState.insertCoins();
    }

    public void takeBackCoins() {
        nowState.takeBackCoins();
    }

    public void turnCrank() {
        nowState.turnCrank();
    }

    public void dispense() {
        nowState.dispense();
    }

}
